<?php
namespace app\common\service;

use think\worker\Server;

class Worker extends Server
{
	// 支持事件回调
	public function onWorkerStart($worker) {
//		print_r($worker);
//		echo 'onWorkerStart'.PHP_EOL;
	}

	public function onWorkerReload($worker) {
	//		echo 'onWorkerReload'.PHP_EOL;
	}

	/**
	 * 当连接建立时触发的回调函数
	 * @param $connection
	 */
	public function onConnect($connection)
	{
		$connection->send( '欢迎进入聊天室');
	}

	public function onMessage($connection, $data) {
		echo $data.PHP_EOL;
		$connection->send($data);
	}

	public function onClose($connection) {
			echo 'onClose'.PHP_EOL;
	}

	public function onError($connection, $code, $msg) {
	        echo "error [ $code ] $msg\n";
	}
}
